
package org.openeai.lite.esb.client;

import org.apache.log4j.Logger;
import org.mule.api.MuleContext;
import org.mule.module.client.MuleClient;
import org.openeai.lite.common.control.ESBController;
import org.openeai.lite.common.exception.OpenEAIException;


public class ESBClient
{

    private Logger log = Logger.getLogger(ESBClient.class);

    public MuleClient getClient() throws OpenEAIException
    {
        MuleClient muleClient = null;
        try
        {
            muleClient = new MuleClient(getContext());
        }
        catch (Exception e)
        {
            log.error("Error instantiating Mule Client: " + e.getCause());
            throw new OpenEAIException(e);
        }
        return muleClient;
    }

    public MuleClient getClient(MuleContext muleContext) throws OpenEAIException
    {
        MuleClient muleClient = null;
        try
        {
            muleClient = new MuleClient(muleContext);
        }
        catch (Exception e)
        {
            log.error("Error instantiating Mule Client: " + e.getCause());
            throw new OpenEAIException(e);
        }
        return muleClient;
    }

    public MuleContext getContext() throws OpenEAIException
    {
        try
        {
            return ESBController.getInstance().getContext();
        }
        catch (Exception e)
        {
            log.error("Error getting Mule context!");
            throw new OpenEAIException(e);
        }
    }

}
